$(function () {
    $(document).on('click', '.m-search-bar', function () {
        location.href = 'views/search_goods.html';
    });
//插入定位box
    var templ = '<span class="box location-box"></span>'
    $(templ).appendTo($("#flow-list"));
    //上滑事件触发瀑布流
    $("html, body").scrollTop(1);
    var index = 1;
    var pageNum = 10;
    $("#flow-list").waterfall({
        itemClass: ".box",
        minColCount: 2,
        spacingHeight: 10,
        isFadeIn: true,
        resizeable: true,
        ajaxCallback: function (success, end) {

            findAllGoodsItem(pageNum, index)
            console.log("调用了一次")
            console.log(index)
            console.log(pageNum)
            success();
            index++;
            end();
            $(".location-box").remove();
        }
    });
    var mySwiper = new Swiper('.swiper-container', {
        autoplay: true,
        pagination: {
            el: '.swiper-pagination',
            dynamicBullets: true,
        },
    });

    $('.weui-navbar__item').on('click', function () {
        $(this).addClass('weui-bar__item_on').siblings('.weui-bar__item_on').removeClass('weui-bar__item_on');
    });

    $('.wanna-buy').on('click', function () {
        location.href = 'wannas.html';
    });

    $(document).on('click', '.box', function () {
        location.href = 'views/goods_detail.html';
    });


    function findAllGoodsItem(pageSize, page) {
        var result = Model.goods.findAllGoodsItem({
            pageSize: pageSize,
            page: page
        });
        if (result.data.length == 0) {
            $('#flow-list').append('<p style="position: absolute;z-index: 9999; bottom: 4.5rem;left: 43%;color: #666666;">没有更多数据了</p>');
        }
        for (var i = 0; i < result.data.length; i++) {
            var item = '<a class="box" href="views/goods_detail.html?id=' + result.data[i].id + '"><img src="' + ((result.data[i].goodsImg.length > 0) ? result.data[i].goodsImg[0].image : '') + '" /><p class="flow-list-name">' + result.data[i].content + '</p>' +
                '<p class="flow-list-price">￥ ' + result.data[i].price + '</p></a>';
            $('#flow-list').append(item);
        }

    }
})